package com.autumn.mybatis.criterion;

import com.autumn.mybatis.mapper.IEntityMapper;
import com.autumn.util.ExceptionUtils;

/**
 * 实体指定更新
 * 
 * @author 杨昌国 2018-12-07 17:47:49
 */
public class EntitySpecifyUpdate<TEntity> extends SpecifyUpdate {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4049534776747599058L;
	private final Class<TEntity> entityClass;

	/**
	 * 实例化 EntityQuery 类新实例
	 * 
	 * @param entityClass 实体类型
	 */
	public EntitySpecifyUpdate(Class<TEntity> entityClass) {
		super(entityClass);
		this.entityClass = ExceptionUtils.checkNotNull(entityClass, "entityClass");
	}

	/**
	 * 获取实体类型
	 * 
	 * @return
	 */
	public final Class<TEntity> getEntityClass() {
		return entityClass;
	}

	/**
	 * 指定更新
	 * 
	 * @param repository 仓储
	 * @return
	 */
	public int update(IEntityMapper<TEntity> repository) {
		ExceptionUtils.checkNotNull(repository, "repository");
		return repository.updateBySpecify(this.builderSection());
	}
}
